var sysParam = {};
var sysParam = function () {
    //本身
    var $this = this;
    this.init = function () {
        //实例化表格
        layuiFunciton.tableInit({
            tableId: 'modelTableId',
            url: '/ngu/notepads/selectNotepadsList',
            id: 'modelId',
            searchFromId: 'searchFrom',
            tableFilter: 'modelList', //表格监听名称,
            page: true,
            cols: [
                [  {
                    field: 'nTitle',
                    title: '记事本标题',
                    align: "rigth"
                },
                {
                field: 'nContent',
                title: '记事本内容',
                align: "rigth",
                sort: true
                },
                {
                    field: 'nCreateTime',
                    title: '创建时间',
                    align: "rigth",
                    sort: true
                },{
                    field: 'nUpdateTime',
                    title: '修改时间',
                    align: "rigth",
                    sort: true,
                    templet: function (d) {
                        if (d.nUpdateTime == "" || d.nUpdateTime == null) {
                            return "<span>-</span>";
                        }
                        return d.nUpdateTime;
                    }
                },
                {
                title: '操作',
                align: "center",
                width: 150,
                templet: '#modelBar',
                fixed: 'right'
                }

                ]
            ],

            tools: {
                edit: {
                    returnData: function (rowData) {
                       console.log(rowData)
                        layer.open({
                            id: 1,
                            type: 1,
                            title: '修改记事本信息',
                            skin: 'layui-layer-rim',
                            area: ['550px', 'auto'],
                            content: ' <div class="row" style="width: 500px;  margin-left:7px; margin-top:10px;height: 227.021px;"">' +
                            '<div class="layui-col-md12">' +
                            '<div class="layui-form-item">' +
                            '<label class="layui-form-label"><span style="color: red">*</span>记事本标题</label>' +
                            '<div class="layui-input-block">' +
                            ' <input type="text" class="layui-input" value="' + rowData.nTitle +
                            '" name="nTitle" id="nTitle" maxlength="20" placeholder="请输入记事本标题">' +
                            '</div>' +
                            '</div>' +
                            '</div>' +
                            '<div class="layui-col-md12">' +
                            '<div class="layui-form-item">' +
                            '<label class="layui-form-label"><span style="color: red">*</span>记事本内容</label>' +
                            '<div class="layui-input-block">' +
                            ' <input type="text" class="layui-input" value="' + rowData.nContent +
                            '"  name="nContent" id="nContent" maxlength="200" placeholder="请输入记事本内容">' +
                            '</div>' +
                            '</div>' +
                            '</div>' +
                            '</div>',
                            btn: ['保存', '取消'],
                            btn1: function (index, layero) {
                                var nTitle = layero.context.getElementById("nTitle").value.replace(/(^\s*)|(\s*$)/g, "");
                                var nContent = layero.context.getElementById("nContent").value.replace(/(^\s*)|(\s*$)/g, "");
                                layuiFunciton.ajaxRequest({
                                    url: '/ngu/notepads/updateNotepads',
                                    method: 'post',
                                    data: {
                                        nTitle: nTitle,
                                        nContent: nContent,
                                        nId: rowData.nId
                                    },
                                    success: function (data) {
                                        layuiFunciton.success("操作成功！", function () {
                                            layer.close(index);
                                            layuiFunciton.refresh('searchFrom', 'modelId');
                                        });
                                    }
                                })
                            },
                            btn2: function (index, layero) {
                                layer.close(index);
                            }
                        });
                    }
                },
                del: {
                    returnData: function (rowData) {
                        layer.confirm('您确定要删除<span style="color: red">“'+(rowData.nTitle.length<=5 ?rowData.nTitle : rowData.nTitle.substring(0,5)+"...")+'”</span>这条数据吗?', {
                            icon: 3,
                            title: '提示信息'
                        }, function (index) {
                            layuiFunciton.ajaxRequest({
                                url: '/ngu/notepads/deleteNotepadsById',
                                method: 'post',
                                data: {
                                    nId: rowData.nId
                                },
                                success: function (data) {
                                    console.log(data)
                                    if (data == 1) {
                                        layuiFunciton.success("操作成功！", function () {
                                            layer.close(index);
                                            layuiFunciton.refresh('searchFrom', 'modelId');
                                        });
                                    }

                                }
                            })
                        });
                    }
                }
            }
        });


    }
    //搜索
    this.find = function () {
        $("#search_btn").click(function () {
            layuiFunciton.refresh('searchFrom', 'modelId', 1);
        });
    }


    //配置新增页面
    this.addNewHtml = function () {
        $("#addMenu_btn").click(function () {
            layer.open({
                id: 1,
                type: 1,
                title: '新增记事本',
                skin: 'layui-layer-rim',
                area: ['550px', 'auto'],
                content: ' <div class="row" style="width: 500px;  margin-left:7px; margin-top:10px;height: 227.021px;">' +
                '<div class="layui-col-md12">' +
                '<div class="layui-form-item">' +
                '<label class="layui-form-label"><span style="color: red">*</span>记事本标题</label>' +
                '<div class="layui-input-block">' +
                ' <input type="text" class="layui-input" value="" name="nTitle" id="nTitle" maxlength="20" placeholder="请输入记事本标题">' +
                '</div>' +
                '</div>' +
                '</div>' +
                '<div class="layui-col-md12">' +
                '<div class="layui-form-item">' +
                '<label class="layui-form-label"><span style="color: red">*</span>记事本内容</label>' +
                '<div class="layui-input-block">' +
                ' <input type="text" class="layui-input" value=""  name="nContent" id="nContent" maxlength="200" placeholder="请输入记事本内容">' +
                '</div>' +
                '</div>' +
                '</div>' +
                '</div>',
                btn: ['保存', '取消'],
                btn1: function (index, layero) {
                    var nTitle = layero.context.getElementById("nTitle").value.replace(/(^\s*)|(\s*$)/g, "");
                    var nContent = layero.context.getElementById("nContent").value.replace(/(^\s*)|(\s*$)/g, "");
                    if (nTitle.length == 0) {
                        layuiFunciton.warn("请填记事本标题！")
                    } else {
                        if (nContent.length > 0) {
                            layuiFunciton.ajaxRequest({
                                url: '/ngu/notepads/addNotepads',
                                method: 'post',
                                data: {
                                    nUserId:nUserId,
                                    nTitle: nTitle,
                                    nContent: nContent
                                },
                                success: function (data) {
                                    layuiFunciton.success("操作成功！", function () {
                                        layer.close(index);
                                        layuiFunciton.refresh('searchFrom', 'modelId');
                                    });
                                }
                            })
                        } else {
                            layuiFunciton.warn("请填写记事本内容！")
                        }
                    }
                },
                btn2: function (index, layero) {
                    layer.close(index);
                }
            });
        });
    }

}
$(function () {
    sysParam = new sysParam();
    sysParam.init(); //初始化
    sysParam.find(); //绑定事件
    sysParam.addNewHtml();
})
